package framework.editor;


import framework.data.GrupoQuarto;
import framework.data.Quarto;
import framework.db.GrupoQuartoManager;
import framework.panes.Editor;
import framework.panes.EditorPane;
import java.awt.Frame;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * QuartoPane.java
 *
 * Created on Jun 10, 2011, 10:24:19 AM
 */
/**
 *
 * @author usuario
 */
public class QuartoEditor extends EditorPane 
{

    private Quarto quarto;

    /**
     * 
     * @param Parent
     * @param quarto
     * @return 
     */
    public static boolean edit( Frame parent, Quarto quarto )
    {
        QuartoEditor pane = new QuartoEditor();
        
        pane.setQuarto( quarto );
        
        return Editor.edit( parent, pane, "Cadastro de Quartos" );
    }

    /** Creates new form QuartoPane */
    public QuartoEditor()
    {
        initComponents();
    }

    /**
     * 
     * @param p 
     */
    private void setQuarto( Quarto q )
    {
        this.quarto = q;
        preencherCampos();
    }
    
    /**
     * 
     */
    private void preencherCampos()
    {
        tfCodigo.setText( String.valueOf( quarto.getCodigo() ) );
        tfNumero.setText( String.valueOf( quarto.getNumero() ) );
        tfAndar.setText( String.valueOf( quarto.getAndar() ) );
        tfGrupo.setText( String.valueOf( quarto.getGrupo() ) );
        
    }
    
    /**
     * 
     */
    @Override
    public void accept()
    {
        quarto.setCodigo( Integer.parseInt( tfCodigo.getText() ) );
        quarto.setNumero( Integer.parseInt( tfNumero.getText() ) );
        quarto.setAndar( Integer.parseInt( tfAndar.getText() ) );
        quarto.setGrupo( Integer.parseInt( tfGrupo.getText() ) );
    }

    @Override
    public String validateInput()
    {
        return "";
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        tfCodigo = new javax.swing.JTextField();
        tfNumero = new javax.swing.JTextField();
        tfAndar = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        tfGrupo = new javax.swing.JTextField();
        tfDescGrupo = new javax.swing.JTextField();

        setLayout(new java.awt.GridBagLayout());

        jLabel1.setText("Código:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 5);
        add(jLabel1, gridBagConstraints);

        jLabel2.setText("Número:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 15, 5, 5);
        add(jLabel2, gridBagConstraints);

        jLabel3.setText("Andar:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
        add(jLabel3, gridBagConstraints);

        jLabel4.setText("Grupo:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 15, 15, 5);
        add(jLabel4, gridBagConstraints);

        tfCodigo.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 15);
        add(tfCodigo, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 5);
        add(tfNumero, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 15);
        add(tfAndar, gridBagConstraints);

        jPanel5.setLayout(new java.awt.GridBagLayout());

        tfGrupo.setPreferredSize(new java.awt.Dimension(60, 20));
        tfGrupo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfGrupoFocusLost(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 15, 5);
        jPanel5.add(tfGrupo, gridBagConstraints);

        tfDescGrupo.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 15, 15);
        jPanel5.add(tfDescGrupo, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        add(jPanel5, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void tfGrupoFocusLost(java.awt.event.FocusEvent evt)//GEN-FIRST:event_tfGrupoFocusLost
    {//GEN-HEADEREND:event_tfGrupoFocusLost
        try
        {
            GrupoQuarto g = GrupoQuartoManager.getInstance().getGrupoQuarto( Integer.parseInt( tfGrupo.getText() ) );
            if (g != null) 
            {
                tfDescGrupo.setText( g.getDescricao() );
            }
        }
        catch ( Exception e ) { }
        
    }//GEN-LAST:event_tfGrupoFocusLost

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JTextField tfAndar;
    private javax.swing.JTextField tfCodigo;
    private javax.swing.JTextField tfDescGrupo;
    private javax.swing.JTextField tfGrupo;
    private javax.swing.JTextField tfNumero;
    // End of variables declaration//GEN-END:variables
}
